library(tidyverse)

crosson = read.csv("data/amicus_crosson.csv") %>% mutate(crosson = mean_score_new) %>%
  select(orgID, crosson)
hansford = read.csv("data/amicus_hansford.csv") %>% mutate(hansford = idealPoint) %>%
  select(orgID, hansford)

barbera_tmp= read.csv("data/barbera_amiciOrgId.csv") %>%
  select(orgID, screen_name)
barbera = read.csv("data/barbera_scores.csv") %>% mutate(barbera = mean,
                                                      screen_name = user) %>%
  left_join(barbera_tmp, by="screen_name") %>% select(orgID, barbera)

dat = crosson %>% full_join(hansford) %>% full_join(barbera)

load("data/bonica_ses.RData")

dat =  out5 %>% mutate(bonica = score) %>% select(orgID, bonica) %>%
  full_join(dat)

gdata::keep(dat, sure=T)

## Check all the pairwise corrs
cor(dat[,-1], use = "complete.obs")
mean(cor(dat[,-1], use = "complete.obs")[1,2:4])

mean(unlist(cor(dat[,-1], use = "complete.obs")[lower.tri(cor(dat[,-1], use = "complete.obs"))]))

## Then take the rowMean of the three measures and write it out
dat = dat %>% rowwise() %>%
  mutate(avg = mean(c(crosson, hansford, barbera), na.rm=T),
         avg2 = mean(c(crosson, hansford, barbera,bonica), na.rm=T))


write.csv(dat, file="data/crosson_hansford_barbera_walk.csv")

rm(list = ls())
gc()